﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class player : MonoBehaviour {

    public float jumpForce = 10f;
    private Rigidbody2D rb;
    public string currentColor;
    public SpriteRenderer spriteRenderer;
    // Use this for initialization
    public Color yellow;
    public Color red;
    public Color blue;
    public Color purp;
	void Start () {

        rb = GetComponent<Rigidbody2D>();
        spriteRenderer = GetComponent<SpriteRenderer>();

        SetRandColor();
	}
	
	// Update is called once per frame
	void Update () {
		

        if(Input.GetMouseButtonDown(0)){

            rb.velocity = Vector2.up * jumpForce;

        }

	}


	private void OnTriggerEnter2D(Collider2D collision)
	{

       
        if(collision.tag!=currentColor){

            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);

        }

        if(collision.tag=="changeyellow"){

            spriteRenderer.color = yellow;
            currentColor = "yellow";

        }else if(collision.tag=="changered"){

            spriteRenderer.color = red;
            currentColor = "red";
        }else if(collision.tag=="changepurp"){

            spriteRenderer.color = purp;
            currentColor = "purp";

        }else if(collision.tag=="changeblue"){

            spriteRenderer.color = blue;
            currentColor = "blue";
        }



	}

    public void SetRandColor(){

        int index = Random.Range(0, 4);
        switch (index)
        {

            case 0:
                currentColor = "red";
                spriteRenderer.color = red;
                break;
            case 1:
                currentColor = "yellow";
                spriteRenderer.color = yellow;
                break;
            case 2:
                currentColor = "purp";
                spriteRenderer.color = purp;
                break;
            case 3:
                currentColor = "blue";
                spriteRenderer.color = blue;
                break;
            default:
                break;
        }

    }
}
